# @File    : select_version.py
# @Project : Airtest_JBL_IOS
# 操作爱思助手选择安装包
from airtest.core.api import *
import pyautogui


class SelectVersion:

    def select_version(self, version, test_device):
        try:
            # wait(Template(r"tpl1704955199440.png", record_pos=(0.088, 0.103), resolution=(1249, 900)))
            wait(Template(r"img/tpl1705303297003.png", record_pos=(0.088, 0.103), resolution=(1248, 904)))
            touch(Template(r"img/tpl1705303297003.png", record_pos=(0.088, 0.103), resolution=(1248, 904)))
            pyautogui.rightClick()
            touch(Template(r"img/Snipaste_2024-01-15_15-17-13.png", record_pos=(0.088, 0.103), resolution=(1249, 900)))
            # touch(Template(r"tpl1704938979901.png", record_pos=(0.38, 0.103), resolution=(1250, 900)))
            wait(Template(r"img/tpl1704938993412.png", record_pos=(-0.172, -0.025), resolution=(1250, 900)))
            touch(Template(r"img/tpl1704939642166.png", record_pos=(0.082, -0.025), resolution=(1250, 900)))
            self.double_click()
            touch(Template(r"img/tpl1704939039092.png", record_pos=(-0.146, -0.104), resolution=(1250, 900)))
            touch(Template(r"img/tpl1704939044705.png", record_pos=(0.114, -0.175), resolution=(1250, 900)))
            wait(Template(r"img/tpl1704939052682.png", record_pos=(0.001, 0.001), resolution=(1250, 900)))
            touch(Template(r"img/tpl1704939056761.png", record_pos=(0.158, 0.053), resolution=(1250, 900)))
            touch(Template(r"img/tpl1704939063768.png", record_pos=(-0.157, -0.175), resolution=(1250, 900)))
            touch(Template(r"img/Snipaste_2024-01-11_10-11-54.png", record_pos=(-0.157, -0.175), resolution=(1250, 900)))
            touch(Template(r"img/tpl1704939127593.png", record_pos=(-0.291, -0.234), resolution=(1250, 900)))
            touch(Template(f"img/V{version}.png", record_pos=(-0.123, -0.063), resolution=(1250, 900)))
            self.double_click()
            if test_device == "耳机":
                touch(Template(r"img/earbud.png", record_pos=(-0.162, 0.002), resolution=(1250, 900)))
            elif test_device == "充电盒":
                touch(Template(r"img/case.png", record_pos=(-0.162, -0.098), resolution=(1250, 904)))
            self.double_click()
            wait(Template(r"img/tpl1704955100827.png", record_pos=(0.0, 0.002), resolution=(1249, 900)))
            touch(Template(r"img/tpl1704955090855.png", record_pos=(0.157, 0.055), resolution=(1249, 900)))
            wait(Template(r"img/tpl1704955163622.png", record_pos=(-0.043, -0.103), resolution=(1249, 900)))
            touch(Template(r"img/tpl1704955172004.png", record_pos=(0.393, -0.274), resolution=(1249, 900)))
            wait(Template(r"img/tpl1705303297003.png", record_pos=(0.088, 0.103), resolution=(1249, 900)))
            touch(Template(r"img/tpl1705303297003.png", record_pos=(-0.139, 0.194), resolution=(1248, 904)))
        except TargetNotFoundError:
            raise TargetNotFoundError

    def double_click(self):
        # 获取当前鼠标位置
        x, y = pyautogui.position()
        # 在当前位置双击左键
        pyautogui.doubleClick(x, y)

        # 鼠标点击右键
        # pyautogui.rightClick()
